package com.gh.resultVo;

import com.gh.enums.HttpCodeEnum;
import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * @author heyu
 * @date 2022:11:06 11:00
 */
import java.io.Serializable;
import java.util.Map;

/**
 * @author heyu
 * @date 2022:11:06 10:00
 * 封装返回结果
 */
@Data
@AllArgsConstructor
public class ResultVo<T> implements Serializable {



    private Integer code;

    private String hintMessage;

    //返回的金额
    private T data;

    //private String customer;


    public ResultVo() {
        this.code = HttpCodeEnum.SUCCESS.getCode();
    }

   

   

    public static ResultVo ok() {
        return new ResultVo();
    }

    public static ResultVo ok(String msg,String customer) {
        return new ResultVo(HttpCodeEnum.SUCCESS.getCode(),msg,null);
    }

    public static ResultVo ok(Map data) {
        return new ResultVo(200,"success",data);
    }
    public static ResultVo error() {
        return ResultVo.error(HttpCodeEnum.SERVER_ERROR);
    }
    public static ResultVo error(int code, String msg) {
        return new ResultVo(code,msg,null);
    }
    public static ResultVo error(HttpCodeEnum enums){
        return ResultVo.error(enums.getCode(),enums.getMessage());
    }
    public static ResultVo bizError(String msg) {
        return ResultVo.error(HttpCodeEnum.SERVER_ERROR.getCode(), msg);
    }

    public boolean isSuccess(){
        return this.code!=null&&this.code.intValue()==HttpCodeEnum.SUCCESS.getCode();
    }
}



/*
@Data
public class ResultVo {

    String msg;

    Object data;

    String reason;


    public static ResultVo success(String msg,Object data,String reason) {
        ResultVo resultVo = new ResultVo();
        resultVo.setMsg(msg);
        resultVo.setData(data);
        resultVo.setReason(reason);
        return resultVo;
    }

    public static ResultVo fail(String msg) {
        ResultVo resultVo = new ResultVo();
        resultVo.setReason(msg);
        return resultVo;
    }

}
*/
